﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core.Unity {
    public class CommandManager {
        Dictionary<string, IXCommand> _commands = new Dictionary<string, IXCommand>();

        public void Add(string id, IXCommand cmd) {
            _commands.Add(id, cmd);
        }

        public void Remove(string id) {
            if (_commands.Keys.Contains(id)) {
                _commands.Remove(id);
            }
        }

        public IXCommand FindCommand(string id) {
            if (_commands.Keys.Contains(id)) {
                return _commands[id];
            }
            return null;
        }

        public IXCommand this[string id] {
            get {
                return this.FindCommand(id);
            }
        }

        public void CreateCommands(object hook) {
            _commands.ToList().ForEach(a => a.Value.OnCreate(hook));
        }
    }
}
